package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.StrategyComment;
import cn.wolfcode.trip.base.query.StrategyCommentQueryObject;
import cn.wolfcode.trip.base.query.StrategyQueryObject;
import cn.wolfcode.trip.base.query.TagQueryObject;
import cn.wolfcode.trip.base.service.IStrategyCommentService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/strategies")
public class StrategyController {
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private IStrategyCommentService strategyCommentService;



   @GetMapping
   public Object listAllByState(@ModelAttribute("qo")StrategyQueryObject qo){
        return strategyService.listAllByState(qo);
    }

    @GetMapping("{strategyId}/strategyComments")
    public Object queryBystrategyId(StrategyCommentQueryObject qo) {
        return strategyCommentService.query(qo);
    }

    @PostMapping("{strategy.id}/strategyComments")
    public Object save(StrategyComment strategyComment,String[] tags){
        strategyCommentService.saveOrUpdate(strategyComment,tags);
        return new JSONResult();
    }

    @GetMapping("{strategyId}/tags")
    public Object queryForTags(TagQueryObject qo) {
       qo.setOrderBy("tag.name desc");
        return strategyCommentService.queryForTags(qo);
    }

}
